<?php
session_start();
include("load-settings.php");

if(!isset($_SESSION['user']))
	header("Location: login.php");

$user = mysql_real_escape_string($_SESSION['user']);
$result = mysql_query("SELECT * FROM user WHERE id = $user");
$row = mysql_fetch_array($result);

if($row['type'] != 2)
	header("Location: home.php");

$page = $_POST['page'];
$per_page = $_POST['per_page'];
$start = ($page-1) * $per_page;

$result = mysql_query("SELECT * FROM order_record WHERE verified_complete = 1 ORDER BY timestamp DESC LIMIT $start, $per_page") or die(mysql_error());

while($row = mysql_fetch_array($result))
{
	$subresult = mysql_query("SELECT * FROM booster_order WHERE order_record = ".$row['id']." ORDER BY timestamp DESC LIMIT 1") or die(mysql_error());
	$subrow = mysql_fetch_array($subresult);

	if(mysql_num_rows($subresult) == 0)
	{
		$booster_row['username'] = "No booster";
	}
	else
	{
		$booster_result = mysql_query("SELECT * FROM user WHERE id = ".$subrow['booster']) or die(mysql_error());
		$booster_row = mysql_fetch_array($booster_result);
	}

	$user_result = mysql_query("SELECT * FROM user WHERE id = ".$row['user']) or die(mysql_error());
	$user_row = mysql_fetch_array($user_result);

	echo "<tr><td>".$row['id']."</td>";
	echo "<td>".$booster_row['username']."</td>";
	echo "<td>".$row['summoner']."</td>";
	echo "<td>".strtoupper($row['region'])."</td>";
	echo "<td>".$booster_row['paypal']."</td>";
	echo "<td>".$row['booster_payout']."</td>";
	echo "<td>".$user_row['paypal']."</td>";
	echo "<td>".$row['payout']."</td>";
	echo "<td><a href='order.php?id=".$row['id']."' class='btn btn-info'>Details</a></td>";
	echo "</tr>";
}
?>